// 求和相关的配置
const  countOptions = {
  // 开启命名空间，帮助 mapState,mapActions,mapMutations,mapGetters 方法获取 countOptions 中的值
  namespaced:true,
  // actions，用于响应组件中的动作
  actions: {
    // context 参数是 缩简版的store
    jiaOdd(context, value) {
      console.log("actions jiaOdd called");
      if (context.state.sum % 2) {
        context.commit("JIA", value);
      }
    },
    jiaWait(context, value) {
      console.log("actions jiaWait called");
      setTimeout(() => {
        context.commit("JIA", value);
      }, 500);
    },
  },
  // mutations，用于操作数据(state)
  mutations: {
    JIA(state, value) {
      console.log("mutations JIA called");
      state.sum += value;
    },
    JIAN(state, value) {
      console.log("mutations JIAN called");
      state.sum -= value;
    },
  },
  // state，用于存储数据(state)
  state: {
    sum: 0,
    school:"清华",
    subject:'计算机',
  },
  // 准备getters 用于将state中的数据进行加工
  getters: {
    bigSum(state) {
      return state.sum * 10
    }
  },
}

export default countOptions 